import request from '@/utils/request'
import { Grade, PaginationParams, PaginationResult } from '@/types'

/**
 * 获取成绩列表
 */
export function getGradeList(params: PaginationParams & { studentId?: number; semester?: string }) {
  return request<PaginationResult<Grade>>({
    url: '/grades',
    method: 'get',
    params
  })
}

/**
 * 获取学生的所有成绩
 */
export function getStudentGrades(studentId: number) {
  return request<Grade[]>({
    url: `/students/${studentId}/grades`,
    method: 'get'
  })
}

/**
 * 创建成绩记录
 */
export function createGrade(data: Partial<Grade>) {
  return request<Grade>({
    url: '/grades',
    method: 'post',
    data
  })
}

/**
 * 更新成绩
 */
export function updateGrade(id: number, data: Partial<Grade>) {
  return request<Grade>({
    url: `/grades/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除成绩
 */
export function deleteGrade(id: number) {
  return request({
    url: `/grades/${id}`,
    method: 'delete'
  })
}

/**
 * 批量导入成绩
 */
export function importGrades(data: Partial<Grade>[]) {
  return request({
    url: '/grades/import',
    method: 'post',
    data: { grades: data }
  })
}

